<%@ page language="java" import="com.sap.mw.jco.IFunctionTemplate" pageEncoding="UTF-8" %>
<%@ page import="com.sap.mw.jco.JCO" %>
<%@ page import="com.weaver.integration.datesource.SAPInterationOutUtil" %>
<%@ page import="com.weaver.integration.log.LogInfo" %>
<%@ page import="weaver.common.DateUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%--流程退回调用QMS接口--%>
<%
    String requestid = request.getParameter("requestid");
    out.println(">>>>>WeaDynamicParaFkpzAction>>>>>requestid=" + requestid + "<br/>");
    String tablename = request.getParameter("tablename");
    out.println(">>>>>WeaDynamicParaFkpzAction>>>>>tablename=" + tablename + "<br/>");
    String type = "1";
    try {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id,bh,fkpzbm,BUKRS,BLART,WAERS,BKTXT,TRADE_ID from " + tablename + " where requestid=?", requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));//id
        String tablenameDtl = Util.null2String(rs.getString("fkpzbm"));//付款凭证表名
        String bh = Util.null2String(rs.getString("bh"));//编号
        String BUKRS = Util.null2String(rs.getString("BUKRS"));//公司代码
        String currentDate = DateUtil.getCurrentDate();
        String BLART = Util.null2String(rs.getString("BLART"));//凭证类型
        String WAERS = Util.null2String(rs.getString("WAERS"));//币种
        String BKTXT = Util.null2String(rs.getString("BKTXT"));//抬头文本
        String TRADE_ID = Util.null2String(rs.getString("TRADE_ID"));//贸易伙伴

        SAPInterationOutUtil outUtil = new SAPInterationOutUtil();
        JCO.Client myConnection = (JCO.Client) outUtil.getConnection(type, new LogInfo());
        myConnection.connect();
        // 实例名
        JCO.Repository myRepository = new JCO.Repository("Repository", myConnection);
        //设置BAPI函数
        IFunctionTemplate ft = myRepository.getFunctionTemplate("ZFI_ACC_DOCUMENT_CREATE");
        JCO.Function bapi = ft.getFunction();
        //输入参数和结构处理
        JCO.ParameterList input = bapi.getImportParameterList();
        input.setValue(bh, "IV_OANUM");
        //输入表的处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();
        JCO.Table t1 = inputtable.getTable("ZPI_FIPOST");
        rs.executeQuery("select * from " + tablenameDtl + " where mainid=?", mainid);
        while (rs.next()) {
            t1.appendRow();
            t1.setValue(mainid, "NUM");
            t1.setValue(BUKRS, "BUKRS");
            t1.setValue(currentDate.replace("-", ""), "BLDAT");
            t1.setValue(currentDate.replace("-", ""), "BUDAT");
            t1.setValue(BLART, "BLART");
            t1.setValue(WAERS, "WAERS");
            t1.setValue(BKTXT, "BKTXT");
            t1.setValue(TRADE_ID, "TRADE_ID");
            t1.setValue(Util.null2String(rs.getString("KOART")), "KOART");
            t1.setValue(Util.null2String(rs.getString("SAKNR")), "HKONT");
            t1.setValue(Util.null2String(rs.getString("DMBTR")), "DMBTR");
            t1.setValue(Util.null2String(rs.getString("WRBTR")), "WRBTR");
            String ZFBDT = Util.null2String(rs.getString("ZFBDT"));
            t1.setValue(ZFBDT.replace("-", ""), "ZFBDT");
            t1.setValue(Util.null2String(rs.getString("KOSTL")), "KOSTL");
            t1.setValue(Util.null2String(rs.getString("AUFNR")), "AUFNR");
            t1.setValue(Util.null2String(rs.getString("POSID")), "POSID");
            t1.setValue(Util.null2String(rs.getString("ANBWA")), "ANBWA");
            t1.setValue(Util.null2String(rs.getString("PRCTR")), "PRCTR");
            t1.setValue(Util.null2String(rs.getString("ZUONR")), "ZUONR");
            t1.setValue(Util.null2String(rs.getString("SGTXT")), "SGTXT");
            t1.setValue(Util.null2String(rs.getString("MATNR")), "MATNR");
            t1.setValue(Util.null2String(rs.getString("MENGE")), "MENGE");
            t1.setValue(Util.null2String(rs.getString("MEINS")), "MEINS");
            t1.setValue(Util.null2String(rs.getString("ZZCFTCCD")), "RSTGR");
            t1.setValue(Util.null2String(rs.getString("XNEGP")), "XNEGP");
            t1.setValue(Util.null2String(rs.getString("MWSKZ")), "MWSKZ");
            t1.setValue(Util.null2String(rs.getString("FAPIAONO")), "FAPIAONO");
            t1.setValue(Util.null2String(rs.getString("FAPIAOCODE")), "FAPIAOCODE");
        }
        out.println(">>>>>ZFI_ACC_DOCUMENT_CREATE>>>>>t1=" + t1 + "<br/>");
        //执行函数
        myConnection.execute(bapi);
        //输出参数和结构处理
        JCO.ParameterList outPrint = bapi.getExportParameterList();
        String IV_BELNR = Util.null2String(outPrint.getValue("IV_BELNR"));
        out.println(">>>>>ZFI_ACC_DOCUMENT_CREATE>>>>>IV_BELNR=" + IV_BELNR);
        //输出表的处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();
        //返回处理结果以及日志
        JCO.Table t = Table00.getTable("ZRETURN");
        out.println(">>>>>ZFI_ACC_DOCUMENT_CREATE>>>>>t=" + t + "<br/>");
        String TYPE = Util.null2String(t.getValue("TYPE"));
        String MESSAGE = Util.null2String(t.getValue("MESSAGE"));
        out.println(">>>>>ZFI_ACC_DOCUMENT_CREATE>>>>>TYPE=" + TYPE + "<br/>");
        out.println(">>>>>ZFI_ACC_DOCUMENT_CREATE>>>>>MESSAGE=" + MESSAGE + "<br/>");
        JCO.releaseClient(myConnection);
    } catch (Exception e) {
        out.println(">>>>>WeaBfarxAction>>>>>Exception=" + e);
    }
%>



